<template>
  <div class="box">
    <van-nav-bar title="实名购票人" left-arrow @click-left="onClickLeft">
      <template #right>
        <van-icon name="ellipsis" @click="showMark" />
      </template>
    </van-nav-bar>
    <van-overlay :show="show">
      <div class="wrapper" @click="closeMark">
        <div class="block">
          <div @click="goHome">
            <van-icon name="wap-home-o" class="block_icon" />
            <span>主页</span>
          </div>
          <div @click="goUser">
            <van-icon name="contact" class="block_icon" />
            <span>我的聚橙</span>
          </div>
        </div>
      </div>
    </van-overlay>
    <div class="realName" v-if="userinfo === '请实名'">
      <div class="wallet">
        <p>您暂未添加实名购票人,快去添加吧</p>
      </div>
      <div class="footer_btn">
        <button @click="goRealNameAdd">添加实名购票人</button>
      </div>
    </div>
    <div class="realName" v-else>
      <van-field label="姓名" :value="realName" readonly class="userinfo" />
      <van-field label="手机号" :value="realTel" readonly class="userinfo" />
      <van-field label="身份证号" :value="realIdCart" readonly class="userinfo" />
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { Icon, NavBar, Overlay, Field, Toast } from 'vant'
import { getUserInfo } from '@/api'
Vue.use(NavBar)
Vue.use(Icon)
Vue.use(Overlay)
Vue.use(Field)
Vue.use(Toast)
export default {
  data () {
    return {
      userinfo: '请实名',
      show: false,
      realName: '',
      realTel: '',
      realIdCart: ''
    }
  },
  mounted () {
    getUserInfo({
      userid: localStorage.getItem('userid'),
      token: localStorage.getItem('token')
    }).then(res => {
      if (res.data.message === 'token验证失败') {
        Toast('您登录的用户信息已过期,请重新登录')
        localStorage.clear()
        setTimeout(() => {
          this.$router.replace('/login')
        }, 1000)
      } else {
        this.userinfo = res.data.data[0].IdCart
        this.realName = res.data.data[0].nickname
        this.realTel = res.data.data[0].tel.substring(0, 3) + '****' + res.data.data[0].tel.substring(7, 11)
        this.realIdCart = res.data.data[0].IdCart.substring(0, 3) + '***********' + res.data.data[0].IdCart.substring(14, 18)
        // console.log(this.userinfo)
      }
    })
  },
  methods: {
    showMark () {
      this.show = true
    },
    onClickLeft () {
      this.$router.go(-1)
    },
    closeMark () {
      this.show = false
    },
    goHome () {
      this.$router.push('/home')
    },
    goUser () {
      if (localStorage.getItem('loginState') !== 'ok') {
        this.$router.push('/login')
      } else {
        this.$router.push('/user')
      }
    },
    goRealNameAdd () {
      this.$router.push('realNameAdd')
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  display: flex;
  position: relative;
  height: 100%;
}
.block {
  width: 1.4rem;
  height: 0.9rem;
  position: absolute;
  top: 0.4rem;
  right: 0.05rem;
  border-radius: 0.05rem;
  background-color: #fff;
  div {
    width: 100%;
    height: 0.44rem;
    line-height: 0.44rem;
    .block_icon {
      font-size: 0.2rem;
      margin: 0 0.13rem;
      float: left;
      margin-top: 0.1rem;
    }
    span {
      float: left;
    }
  }
  div:nth-of-type(1) {
    border-bottom: 1px solid #f2f2f2;
  }
}
.wallet {
  width: 100%;
  height: auto;
  p {
    text-align: center;
    height: 0.18rem;
    line-height: 0.18rem;
    font-size: 0.12rem;
    color: #999999;
    margin-top: 1rem;
  }
}
.realName {
  width: 100%;
  height: auto;
  /* padding: 0 0.15rem; */
  .userinfo {
    margin: 0 4%;
    width: 92%;
  }
}
.footer_btn {
  width: 100%;
  height: 0.47rem;
  margin-bottom: 0.2rem;
  padding: 0 0.15rem;
  position: fixed;
  bottom: 0;
  z-index: 100;
  button {
    background: linear-gradient(#ff6742, #ff6742),linear-gradient(#ffde00, #ffde00);
    height: 0.47rem;
    line-height: 0.47rem;
    width: 100%;
    border: none;
    color: white;
    font-size: 0.18rem;
    border-radius: 0.26rem;
  }
}
.van-field__label {
  margin: 0 15px;
}
/deep/ .van-nav-bar {
  border-bottom: 1px solid #ebebeb;
}
/deep/ .van-icon-ellipsis {
  font-size: 0.2rem;
  color: #232323;
}
/deep/ .van-icon-arrow-left {
  font-size: 0.2rem;
  color: #232323;
}
/deep/ .van-field {
  width: 100%;
  height: 0.6rem;
  padding: 0;
  color: #232323;
  font-size: 0.16rem;
  line-height: 0.6rem;
  border-bottom: 1px solid #EEEEEE;
}
</style>
